package engine.graphics.vfx
{
	import engine.graphics.anim.*;
	import engine.graphics.particles.*;
	import engine.loaders.*;
	import engine.math.*;
	
	public class RxWorldFXParams
	{
		protected var m_type:uint;
		protected var m_name:String;
		protected var m_startTime:Number;
		protected var m_endTime:Number;
		protected var m_timeScale:Number;
		protected var m_offset:RxVector4;
		protected var m_rotation:RxVector4;
		protected var m_worldMatrix:RxMatrix4x4;
		protected var m_depthBias:Number;
		protected var m_layer:uint;
		protected var m_animColor:RxAnimatedParamVector4;
		protected var m_animEmissive:RxAnimatedParamScalar;
		protected var m_animUVTransform:RxAnimatedParamUVTransform;
		protected var m_animScale:RxAnimatedParamScalar;
		protected var m_jointID:int;
		protected var m_tracking:Boolean;
		protected var m_ignoreOrientation:Boolean;
		protected var m_quadWidth:Number;
		protected var m_quadHeight:Number;
		protected var m_emitterParams:RxParticleEmitterParams;
		public static var SPRITE:uint = 0;
		public static var QUAD:uint = 1;
		public static var MESH:uint = 2;
		public static var PARTICLES:uint = 3;
		public static var POINT_LIGHT:uint = 4;
		
		public function RxWorldFXParams(xml:XML)
		{
			this.m_quadWidth = 0;
			this.m_quadHeight = 0;
			
			var type:* = xml.@type;
			if (type == "Sprite")
			{
				this.m_type = SPRITE;
				this.m_quadWidth = xml.@width;
				this.m_quadHeight = xml.@height;
			}
			else if (type == "Mesh")
			{
				this.m_type = MESH;
			}
			else if (type == "quad")
			{
				this.m_type = QUAD;
				this.m_quadWidth = xml.@width;
				this.m_quadHeight = xml.@height;
			}
			else if (type == "particles")
			{
				this.m_type = PARTICLES;
				this.m_quadWidth = xml.@width;
				this.m_quadHeight = xml.@height;
				this.m_emitterParams = new RxParticleEmitterParams();
				this.m_emitterParams.ParseFromXML(xml.emitter);
			}
			else if (type == "pointLight")
			{
				this.m_type = POINT_LIGHT;
			}
			else
			{
				return;
			}
			this.m_name = xml.@name;
			this.m_startTime = xml.@startTime;
			this.m_endTime = xml.@endTime;
			this.m_timeScale = 1;
			this.m_offset = new RxVector4();
			
			var offset:* = xml.@offset;
			if (offset != "")
			{
				this.m_offset.CopyFromString(offset);
			}
			this.m_offset.w = 1;
			this.m_rotation = new RxVector4();
			
			var rotation:* = xml.@rotation;
			if (xml.@rotation != "")
			{
				this.m_rotation.CopyFromString(rotation);
			}
			this.m_rotation.w = 0;
			this.m_worldMatrix = new RxMatrix4x4();
			this.m_worldMatrix.RotateX(this.m_rotation.x * (Math.PI / 180));
			this.m_worldMatrix.PostMulRotateY(this.m_rotation.y * (Math.PI / 180));
			this.m_worldMatrix.PostMulRotateZ(this.m_rotation.z * (Math.PI / 180));
			this.m_worldMatrix.PostMulTranslate(this.m_offset.x, this.m_offset.y, this.m_offset.z);
			var depthBias:* = xml.@depthBias;
			this.m_depthBias = depthBias == "" ? (0) : (Number(depthBias));
			
			var layer:* = xml.@layer;
			this.m_layer = layer == "" ? (0) : (uint(layer));
			this.m_animColor = null;
			if (xml.animColor && xml.animColor.length())
			{
				this.m_animColor = new RxAnimatedParamVector4();
				this.m_animColor.SetupFromXML(xml.animColor);
			}
			this.m_animEmissive = null;
			if (xml.animEmissive && xml.animEmissive.length())
			{
				this.m_animEmissive = new RxAnimatedParamScalar();
				this.m_animEmissive.SetupFromXML(xml.animEmissive);
			}
			this.m_animUVTransform = null;
			if (xml.animUVTransform && xml.animUVTransform.length())
			{
				this.m_animUVTransform = new RxAnimatedParamUVTransform();
				this.m_animUVTransform.SetupFromXML(xml.animUVTransform);
			}
			this.m_animScale = null;
			if (xml.animScale && xml.animScale.length())
			{
				this.m_animScale = new RxAnimatedParamScalar();
				this.m_animScale.SetupFromXML(xml.animScale);
			}
			
			var joint:* = xml.@joint;
			this.m_jointID = RxLoader3D.GetJointID(joint);
			this.m_tracking = xml.@tracking == "1" ? (true) : (false);
			this.m_ignoreOrientation = xml.@ignoreOrientation == "1" ? (true) : (false);
		}
		
		public function SetTimeScale(param1:Number) : void
		{
			this.m_timeScale = param1;
		}
	}
}